package com.zzy.controller;

import com.zzy.datagridlist.Datagrid;
import com.zzy.model.Leave;
import com.zzy.service.FlowService;
import com.zzy.service.FlowStepService;
import com.zzy.service.LeaveService;
import com.zzy.service.UtilService;
import com.zzy.util.AjaxMsg;
import com.zzy.util.StatusCode;
import com.zzy.util.UtilJson;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@Controller()
@RequestMapping("leave")
public class LeaveController {

    @Autowired
    private LeaveService leaveService;
    @Autowired
    private UtilService utilService;
    @Autowired
    private FlowService flowService;
    @Autowired
    private FlowStepService flowStepService;

    /**跳转到列表页面*/
    @RequestMapping(value="index")
    public String index(HttpServletRequest request, HttpServletResponse response){
       return "page/leave/leave_index";
    }
    /**获取数据表格内容*/
    @RequestMapping(value="gird")
    @ResponseBody
    public void gird(HttpServletRequest request, HttpServletResponse response){
        Datagrid.list(request,response,Leave.class,utilService);
    }


    /**跳转到详情页面*/
    @RequestMapping(value="load")
    public String load(HttpServletRequest request, HttpServletResponse response){
        String id = request.getParameter("id");
        if(id!=null){
            Leave leave = leaveService.getByID(id);
            request.setAttribute("model",leave);
            request.setAttribute("load",request.getParameter("load"));
        }
        return   "page/leave/leave_detail";

    }

    /**添加或者修改*/
    @RequestMapping(value="opt")
    @ResponseBody
    public void addOrUpdate(Leave model, HttpServletRequest request, HttpServletResponse response){
        if(model!=null && model.getId()!=null && model.getId().trim().equals("")){//保证传递的ID不是空值 而是null
            model.setId(null);
        }
        UtilJson.jsonPrintln(leaveService.saveOrUpdate(model),response);
    }

    /**删除*/
    @RequestMapping(value="delete")
    @ResponseBody
    public void delete(String id,HttpServletRequest request, HttpServletResponse response){
        UtilJson.jsonPrintln(leaveService.del(id),response);;
    }

}
